
package com.idea.rdftree;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;

import javax.swing.JFrame;
import javax.swing.JTree;
import javax.swing.ToolTipManager;

//import org.idea.common.features.RdfFeatureSet;

import com.hp.hpl.jena.rdf.model.*;


public class Main {
  //  public static String SYSTEM_PROPS = "./etc/system.rdf";
    public static String MASTER_FEATURES_URI = "http://ideagraph.org/xmlns/ideagraph/default";

    //	public static	FeatureSet 	masterFeatures = new TypedFeatures(MASTER_FEATURES_URI);
    public static void main(String[] args) {
    //    RdfFeatureSet masterFeatures = new RdfFeatureSet(MASTER_FEATURES_URI);
        String filename = "/home/danny/workspace/N2/playground/danja/meta/foaf/me2.rdf";

        try {
       //     masterFeatures.load(filename);

            //systemProperties.load(filename);
        } catch(Exception exception) {
            exception.printStackTrace();
        }

        /*
        FeatureSet         systemFeatures =
                new RdfFeatureSetTreeNode(
                                masterFeatures.getURI() + "/system");
        */
        /*
        FeatureSetTreeModel model = new FeatureSetTreeModel(        masterFeatures);
        System.out.println("count = "+model.getChildCount(model.getRoot()));
        System.out.println("root = "+model.getRoot());
        FeatureTree tree = new FeatureTree(model);
        */
      //  Model model = masterFeatures.getModel();
        Model model = ModelFactory.createDefaultModel();

        RDFReader arp = model.getReader();
        // Do not warn on use of unqualified RDF attributes.
        arp.setProperty("WARN_UNQUALIFIED_RDF_ATTRIBUTE","EM_IGNORE");
        //.getRDFReader();
        // m = null; // m is new`6tt45ro longer needed.
       
            InputStream in;
            try {
                in = new FileInputStream(filename);
        
            arp.read(model,in,"");
            in.close();
            } catch (FileNotFoundException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();	
            }
        RdfNodeMap nodeMap = new RdfNodeMap(model);
        RootNode root = new RootNode(nodeMap);
        root.setModel(model);
nodeMap.interpret();
        /*
        tree.getSelectionModel().setSelectionMode
        (TreeSelectionModel.SINGLE_TREE_SELECTION);
        */
        RdfTreeModel treeModel = new RdfTreeModel(root, model, nodeMap);
        JTree tree = new JTree(treeModel);
        tree.putClientProperty("JTree.lineStyle", "Angled");
        ToolTipManager.sharedInstance().registerComponent(tree);
        tree.setCellRenderer(new RdfTreeCellRenderer());

        JFrame frame = new JFrame();
        frame.getContentPane().add(tree);
        frame.pack();
        frame.show();
    }
}
